/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Other;

import Gmail.NhanEmail;
import java.awt.Checkbox;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.internet.InternetAddress;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author JB
 */
public class MyTableModel extends AbstractTableModel {

    public void InsertData() {
        for (int i = 0; i < NhanEmail.messages.length; i++) {
            try {
                Multipart mp = (Multipart) NhanEmail.messages[i].getContent();
                //String file = mp.getBodyPart(1).getFileName();
//                Boolean chkFile;
//
//                for (int j = 0; j < mp.getCount(); j++) {
//                    MimeBodyPart bp[] = null;
//                    bp[j] = (MimeBodyPart) mp.getBodyPart(j);
//                }

                data = new Object[]{
                    new Boolean(false), //0-checkbox
                    InternetAddress.toString(NhanEmail.messages[i].getFrom()), //1-nguoigui
                    NhanEmail.messages[i].getSubject(), //2-tieude
                    //                            message.getReceivedDate().getYear() + 1900
                    //                            + "/" + message.gextReceivedDate().getMonth()
                    //                            + "/" + message.getReceivedDate().getDate(),
                    NhanEmail.messages[i].getSentDate(), //3-ngaygui
                    mp.getBodyPart(0).getContent().toString(), //4-noidung
                //(messages[i].getFileName()).isEmpty() ? lbAttach : "", //4
                //                            chkFile == true ? (JLabel) lbAttach : "", //5-cofilekhong
                //                            chkFile == true ? mp.getBodyPart(1).getFileName() : ""}); //6-tenfile
                //(messages[i].getFileName()).isEmpty() ? new JLabel(icon) : "a"});
                };
            } catch (IOException ex) {
                Logger.getLogger(MyTableModel.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MessagingException ex) {
                Logger.getLogger(MyTableModel.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }
    private String[] columnNames = {"#",
        "Người gửi",
        "Tiêu đề",
        "Ngày gửi",
        "Nội dung"
    //"Tập tin"
    };
    private Object[] data = null;

    public int getRowCount() {
        return data.length;
    }

    /*
     * JTable uses this method to determine the default renderer/ editor for
     * each cell. If we didn't implement this method, then the last column would
     * contain text ("true"/"false"), rather than a check box.
     */
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        if (col < 2) {
            return false;
        } else {
            return true;
        }
    }

    /*
     * Don't need to implement this method unless your table's data can change.
     */
    @Override
    public int getColumnCount() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
